//数量加减按钮
function changeCut(i, type){
	if(type == 1){
		productList.list[i].quantity++
	}else{
		if(productList.list[i].quantity > 1){
			productList.list[i].quantity--
		}
	}
	productList.list[i].productPackage.original_price = productList.list[i].productPackage.price*productList.list[i].quantity
	
	var priceAll = 0;
	for(var i=0;i<productList.list.length;i++){
	 	if(productList.list[i].productPackage.checked == "checked"){
	 		priceAll += productList.list[i].quantity*productList.list[i].productPackage.price
	 	}
	}
	$("#priceAll").text(priceAll)
	
	$("#tmpl_div_content").setTemplateURL('tmpl/myShoppingCartTmpl.html');
	$("#tmpl_div_content").setParam("width", window.screen.width);
	$("#tmpl_div_content").setParam("height", window.screen.height); 
	$("#tmpl_div_content").processTemplate(productList);
}

// 选中后更改数据状态，用来保持状态
function onchangeNum(i){
	if(productList.list[i].productPackage.checked == null || productList.list[i].productPackage.checked == "no"){
		productList.list[i].productPackage.checked = "checked"
	}else{
		productList.list[i].productPackage.checked = "no"
	}
	
	var priceAll = 0;
	var checkall = true
	for(var i=0;i<productList.list.length;i++){
	 	if(productList.list[i].productPackage.checked == "checked"){
	 		priceAll += productList.list[i].quantity*productList.list[i].productPackage.price
	 	}else{
	 		checkall = false
	 	}
	}
	
	//全选
	//onchangeAll($("#img_check_all"), !checkall)
	if(checkall){
		$("#img_check_all").attr("src","../image/input_s.png")
	}else{
		$("#img_check_all").attr("src","../image/input.png")
	}
	$("#priceAll").text(priceAll)
	
	$("#tmpl_div_content").setTemplateURL('tmpl/myShoppingCartTmpl.html');
	$("#tmpl_div_content").setParam("width", window.screen.width);
	$("#tmpl_div_content").setParam("height", window.screen.height);  
	$("#tmpl_div_content").processTemplate(productList);
}

//全选
function onchangeAll(t, unSelected){
	if($("#img_check_all").attr('src').indexOf('input_s')>0 || unSelected == true){
	 	for(var i=0;i<productList.list.length;i++){
	 		productList.list[i].productPackage.checked = "no"
	 	}
	 	$("#img_check_all").attr("src","../image/input.png")
	}else{
	 	for(var i=0;i<productList.list.length;i++){
	 		if(productList.status == 1 && productList.list[i].is_valid == 0){
	 			productList.list[i].productPackage.checked = "no"
	 		}else{
	 			productList.list[i].productPackage.checked = "checked"
	 		}
	 	}
	 	$("#img_check_all").attr("src","../image/input_s.png")
	}
	
	var priceAll = 0;
	for(var i=0;i<productList.list.length;i++){
	 	if(productList.list[i].productPackage.checked == "checked"){
	 		priceAll += productList.list[i].quantity*productList.list[i].productPackage.price
	 	}
	}
	$("#priceAll").text(priceAll)
	$("#tmpl_div_content").setTemplateURL('tmpl/myShoppingCartTmpl.html');
	$("#tmpl_div_content").setParam("width", window.screen.width);
	$("#tmpl_div_content").setParam("height", window.screen.height); 
	$("#tmpl_div_content").processTemplate(productList);
}

function gotoHome(){
	window.location.href="home.html"
}
